package app.auto.runner.base.utility;

import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;

import com.aliang.auto.R;

import app.auto.runner.base.intf.FunCallback;

public class MenuUtil {
    public static void showPopupMenu(View view, FunCallback funCallback) {
        // View当前PopupMenu显示的相对View的位置
        PopupMenu popupMenu = new PopupMenu(view.getContext(), view);
        // menu布局
        popupMenu.getMenuInflater().inflate(R.menu.menu_stuff, popupMenu.getMenu());
        // menu的item点击事件
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
//                switch (item.getItemId()) {
//                    case R.id.action_del:
//
//                        break;
//                    case R.id.action_copy:
//
//                        break;
//                }
                if (funCallback != null) {
                    funCallback.onCallback(item.getTitle(),null);
                }
                return false;
            }
        });
        // PopupMenu关闭事件
        popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
            @Override
            public void onDismiss(PopupMenu menu) {
            }
        });
        popupMenu.show();
    }

    public static void showPopupMenu(int menuid,View view, FunCallback funCallback) {
        // View当前PopupMenu显示的相对View的位置
        PopupMenu popupMenu = new PopupMenu(view.getContext(), view);
        // menu布局
        popupMenu.getMenuInflater().inflate(menuid, popupMenu.getMenu());
        // menu的item点击事件
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
//                switch (item.getItemId()) {
//                    case R.menuid.action_del:
//
//                        break;
//                    case R.menuid.action_copy:
//
//                        break;
//                }
                if (funCallback != null) {
                    funCallback.onCallback(item.getTitle(),null);
                }
                return false;
            }
        });
        // PopupMenu关闭事件
        popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
            @Override
            public void onDismiss(PopupMenu menu) {
            }
        });
        popupMenu.show();
    }
}
